<script>
	import {
		mapState,
		mapMutations
	} from "vuex";
	import {
		getInfo
	} from "@/business/systeminfo.js";
	import {
		checkUpdateVersion
	} from "@/business/updateManager.js";
	import {
		timer
	} from "@/utils/timer.js"
	import {
		apiMixUrlKeyApi,
		apiMixUrlApi
	} from "@/api/assemb";
	import {
		vipType,
	} from '@/business/login.js';

	export default {
		globalData: {
			couponTime: 5 * 60 * 1000,
			endTime: 0,
			frequency: 2,
			keyer: null,
			iosPay:2, //控制ios充值方式 弃用
			resourceAppid: "wxce1468e05a9fe673",
			// // 资源方环境 ID
			resourceEnv: "xzy-8gkjj1544349b4cb",
			National:1,
			// Liupaer:false,//流式控制参数的显示隐藏
		},
		onLaunch: function() {
			/* 自定义导航高度 */
			// 状态栏高度
			this.globalData.statusBarHeight = uni.getSystemInfoSync().statusBarHeight;
			
			let custom = uni.getMenuButtonBoundingClientRect();
			
			// 导航栏高度(标题栏高度) = 胶囊高度 + (顶部距离 - 状态栏高度) * 2
			this.globalData.navigationBarHeight = custom.height + (custom.top - this.globalData.statusBarHeight) * 2;
			
			// 总体高度 = 状态栏高度 + 导航栏高度
			this.globalData.navHeight = this.globalData.navigationBarHeight + this.globalData.statusBarHeight;
			let update = uni.getStorageSync('update');
			if (update != uni.getAccountInfoSync().miniProgram.version) {
				try {
					uni.clearStorageSync();
				} catch (e) {}
				uni.setStorageSync('update', uni.getAccountInfoSync().miniProgram.version);
			}
			// let config = {
			// 	interval: 1, //间隔天数，间隔为整数
			// 	runNow: false, //是否立即运行
			// 	time: "09:20:00" //执行的时间点 时在0~23之间
			// }
			// timer(config, this.func)
			checkUpdateVersion();
			let initialTime = 5 * 60 * 1000;
			uni.setStorageSync("couponTime", initialTime);
			if (!wx.getStorageSync("baseinfo").openid) {
				getInfo();
			}
			this.getAccessToken()
			this.getDate();
			// this.getEarnCoins();
		},
		onLoad(option) {},
		onShow: function() {
			console.log("App Show");
			if (uni.getStorageSync('service')) {
				vipType(false);
				uni.removeStorageSync('service');
			}
			// 调取会员信息
			vipType(false);
		},
		onHide: function() {
			console.log("App Hide");
		},
		methods: {
			// 获取剩余次数
			getEarnCoins() {
				apiMixUrlApi({}, 1042, 'GetPaymentInfo').then(data => {
					if (data.descinfo == "success") {
						console.log(data,'这是data')
						if (data.coinsupdateindex > 0) {
							uni.setStorageSync('frequency', data.coins)
						} else {
							// let prams = {
							// 	coins: 3,
							// 	descinfo: '新用户赠送'
							// }
							// apiMixUrlKeyApi(prams, '1031', 'EarnCoins').then(res => {
							// 	uni.setStorageSync('frequency', res.data.coins)
							// })
						}
					}
				});
			},
			// 清理看广告次数
			getDate() {
				if (uni.getStorageSync('today') == 0) {
					let date1 = new Date(); // 获取当前日期和时间
					uni.setStorageSync("today", date1);
				} else {
					let date1 = new Date(); // 获取当前日期和时间
					let date2 = uni.getStorageSync("today"); // 从缓存拿存储时间
					if (date1.getFullYear() === date2.getFullYear() &&
						date1.getMonth() === date2.getMonth() &&
						date1.getDate() === date2.getDate()) {
						console.log("这是今天");
					} else {
						console.log("这不是今天");
						uni.setStorageSync('attemptCount', 0)  //文案提取次数重置
						uni.setStorageSync('watchad', 0)
						uni.setStorageSync("today", date1);
					}
				}
			},
			getAccessToken() {
				uni.request({
					url: 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=CWIZRKYuYCdxaxpRY4IAS8l3&client_secret=pFsZMSGpas1cezGfiddi0AwZxMU9vmaG',
					method: "POST",
					success(res) {
						console.log(res, 'getAccessToken');
						getApp().globalData.accessToken = res.data.access_token
					}
				})
			}
		}
	};
</script>

<style lang="scss">
	/*每个页面公共css */
	/* 注意要写在第一行，同时给style标签加入lang="scss"属性 */
	@import "@/uni_modules/uview-ui/index.scss";
</style>